/*
 * Amkai Enterprise Solution (AES.) 
 * Copyright 2004 by Amkai(TM), Inc.
 * www.amkai.com
 * 
 * Project: webservice
 * Package: com.amkai.aes.webservice.binary.objecthandler
 * File: UploadCommitHandler.java
 * Created: Jan 17, 2006 3:16:33 PM
 * Author: johnny 
 * 
 */
package com.amkai.aes.webservice.binary.objecthandler;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.amkai.aes.aescommon.service.binary.job.BinaryUploadCommitJob;
import com.amkai.aes.aescommon.store.binary.BinaryCollection;
import com.amkai.aes.aescommon.store.binary.BinaryCollectionKind;
import com.amkai.aes.webservice.binary.JobObjectHandler;
import com.amkai.common.extensions.hibernate.config.SiteManager;
import com.amkai.common.extensions.hibernate.config.manager.SessionManager;
import com.sun.corba.se.pept.encoding.InputObject;

/**
 * UploadCommitHandler
 * @author johnny
 * Description:
 *
 */
public class UploadCommitHandler implements JobObjectHandler<BinaryUploadCommitJob, Serializable, Serializable> {
	private static final Log log = LogFactory.getLog(UploadCommitHandler.class);

	/** 
	 * Overriden method
	 * @param job
	 * @param object
	 * @return
	 * @throws Exception
	 * @see com.amkai.aes.webservice.binary.JobObjectHandler#process(E, InputObject)
	 * 
	 */
	public Serializable process(BinaryUploadCommitJob job, Serializable object) throws Exception {
		Long id = job.getBinaryCollectionId();
		SessionManager sm = SiteManager.Start();
		
		try {
//			sm.openSession(LogInterceptor.newInstance(null, null, sm.getFactory().getSessionFactory()));
			sm.openSession();
			sm.openTransaction();
			BinaryCollection coll = (BinaryCollection)sm.get(BinaryCollection.class, id);
			coll.setKind(BinaryCollectionKind.COMMITED);
			sm.update(coll);
			sm.commitTransaction();
		}
		catch (Exception e) {
			sm.rollbackTransaction();
			log.error("", e);
			throw e;
		}
		finally {
			sm.closeSession();
		}
		return null;
	}

}
